//
//  MyTabBar.m
//  YAMainProject
//
//  Created by 郑逸凯 on 2018/10/30.
//  Copyright © 2018年 郑逸凯. All rights reserved.
//

#import "MyTabBar.h"

@interface MyTabBar ()

@property (nonatomic,strong)UIImageView *centerImageView;
@property (nonatomic,strong)UILabel *label;

@end

@implementation MyTabBar

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"plus_Last"] forState:UIControlStateNormal];
        btn.bounds = CGRectMake(0, 0, 64, 64);
        
        self.centerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"plusX_Last"]];
        self.centerImageView.bounds = CGRectMake(0, 0, 64 * 0.6, 64 * 0.6);
        
        self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 64, 12)];
        self.label.textColor = RGBToColor(145, 145, 145);
        self.label.textAlignment = NSTextAlignmentCenter;
        self.label.font = [UIFont boldSystemFontOfSize:10];
        self.label.text = @"长按开始直播";
        
        self.centerBtn = btn;
        [self addSubview:btn];
        [self addSubview:self.centerImageView];
        [self addSubview:self.label];
        
        
        
        
    }
    return self;
}

- (void)layoutSubviews
{
    
    [super layoutSubviews];
    
    self.centerBtn.center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.05);
    self.centerImageView.center = self.centerBtn.center;
    self.label.center = CGPointMake(self.bounds.size.width * 0.5, 34 + 6);

    int index = 0;
    CGFloat wigth = self.bounds.size.width / 5;
    
    for (UIView* sub in self.subviews) {
        
        if ([sub isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            sub.frame = CGRectMake(index * wigth, self.bounds.origin.y, wigth, self.bounds.size.height - 2);
            
            index++;
            
            if (index == 2) {
                index++;
            }
        }
    }
}



- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    
    if (self.isHidden == NO) {
        
        CGPoint newPoint = [self convertPoint:point toView:self.centerBtn];
        
        if ( [self.centerBtn pointInside:newPoint withEvent:event]) {
            return self.centerBtn;
        }else{
            
            return [super hitTest:point withEvent:event];
        }
    }
    
    else {
        return [super hitTest:point withEvent:event];
    }
}
@end
